﻿
//        $(document).ready(function() {
//            $("#txtename").autocomplete("../ajax/GetUser.aspx?type=1", { minChars: 2, extraParams: { uname: function() { return escape($('#txtename').val()); } }, scrollHeight: 350, width: 150, max: 100 });
//            document.getElementById("txtename").focus();
//            $("#txtDistrict").autocomplete("../ajax/GetUser.aspx?type=2", { minChars: 2, extraParams: { uname: function() { return escape($('#txtDistrict').val()); } }, scrollHeight: 350, width: 150, max: 100 });
//            document.getElementById("txtDistrict").focus();

//        });


        var currentPage = 1; // 当前页
        var pageSize = 20; // 每页显示多少条
        var pageall = 0; // 总页数
        var total = 0; // 总记录数
        window.onload = function divajaxlist(currentPage) {
            var startday = document.getElementById('iStartDay').value;
            var endday = document.getElementById('iEndDay').value;
//            var ename = document.getElementById('txtename').value;
//            var district = document.getElementById('txtDistrict').value;
//            var department = document.getElementById('txtDepartment').value;
            document.getElementById('div0').innerHTML = "<div><img src=\"../../images/loading.gif\" /></div>";
            $.ajax({
                type: "POST",
                url: "../AjaxServer.aspx",
                dataType: 'json',
                data: "alt=ShareList&startday=" + startday + "&endday=" + endday + "&pagesize=" + pageSize + "&page=" + currentPage + "",
                processData: false,
                timeout: '10000',
                success: function(json) {
               
                    divlist(json);
                },
                error: function() {
               
                document.getElementById('div0').innerHTML = "系统繁忙";
                }

            });
        }
        function divlist(msg) {
            //var json = eval("(" + response + ")");

            var json = msg;
            var record = json.record;
            var page = json.page;
            currentPage = page.currentpage;

            pageall = parseInt(page.pages);
            total = page.intResult;
           
            if (record == null || record.length == 0) {
                $("#div0").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
                return;
            }
            $("#div0").html(""); // 显示列表
            var arr = [];
            arr.push("<table  border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce' class=\"table1\" valign='top' >");
            arr.push("<tr bgcolor=\"#353c44\" >");
            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
            arr.push("<div >楼盘名称</div>");
            arr.push("</td>");
            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:100px;'  >");
            arr.push("<div >我司</div>");
            arr.push("</td>");
       
            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
            arr.push("<div >深圳</div>");
            arr.push("</td>");
            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
            arr.push("<div >占有率</div>");
            arr.push("</td>");
//            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
//            arr.push("<div >行政区</div>");
//            arr.push("</td>");
//            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
//            arr.push("<div >分行</div>");
//            arr.push("</td>");
//            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
//            arr.push("<div >营业部</div>");
//            arr.push("</td>");
//            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
//            arr.push("<div >区域</div>");
//            arr.push("</td>");
//            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
//            arr.push("<div >全市</div>");
//            arr.push("</td>");
//            arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
//            arr.push("<div >我司</div>");
//            arr.push("</td>");
            arr.push("</tr>");
            for (var i = 0; i < record.length; i++) {

                if (i % 2 == 0)
                    arr.push("<tr bgcolor='#FFFFFF'>");
                else
                    arr.push("<tr bgcolor='#EEEDED'>");
                arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");
                arr.push(record[i].sharename);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(record[i].sharecompany);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(record[i].sharecity);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                if (record[i].sharecity != 0)
                    arr.push(tootoDecimal(toDecimal2(record[i].sharecompany / record[i].sharecity) * 100) + '%');
                else
                    arr.push(0);
                arr.push("</td>");
//                arr.push("<td height='20' class='STYLE6'>");
//                arr.push(record[i].shareregion);
//                arr.push("</td>");
//                arr.push("<td height='20' class='STYLE6'>");
//                arr.push(record[i].sharebranch);
//                arr.push("</td>");
//                arr.push("<td height='20' class='STYLE6'>");
//                arr.push(record[i].sharedepartment);
//                arr.push("</td>");
//                arr.push("<td height='20' class='STYLE6'>");
//                arr.push(record[i].sharedistrict);
//                arr.push("</td>");
//                arr.push("<td height='20' class='STYLE6'>");
//                arr.push(record[i].sharecity);
//                arr.push("</td>");
//                arr.push("<td height='20' class='STYLE6'>");
//                arr.push(record[i].sharecompany);
//                arr.push("</td>");
                arr.push("</tr>");
            }
            arr.push("</table>");
            arr.push("<div id=\"divPage\" ></div>");
            document.getElementById('div0').innerHTML = arr.join('');
            $("#divPage").html(""); // 清空
            if (pageall > 1) {

                var pageHtml = LexunJS.showPage(currentPage, pageall, "divajaxlist"); // 分页
                $("#divPage").html(pageHtml);
            }
        }
        
        
        
        // 级联加载列表
        function loadCity(sCity1, sCity2) {
            var parentid = document.getElementById(sCity1).value;
            if (parentid <= 0) {
                document.getElementById(sCity2).length = 0;
                LexunJS.selectAddOption(document.getElementById(sCity2), "全部", 0);
                return false;
                
            }

            $.ajax({
                type: "POST",
                url: "../AjaxServer.aspx",
                dataType: 'json',
                data: "alt=area_list&parentid=" + parentid,
                processData: false,
                timeout: '10000',
                success: function(json) {

                    loadCity2CallBack(json, sCity2);
                },
                error: function() {
                    alert("加载失败！");
                }

            });
        }

        // 加载城市列表回调
        function loadCity2CallBack(msg, sCity2) {
            // var json = eval("(" + response + ")");
            var json = msg;
            var record = json.record;
           
            $("#" + sCity2).html("");
            var obj = document.getElementById(sCity2);
            LexunJS.selectAddOption(obj, "全部", 0);

            if (record == null || record.length == 0)
                return;

            var recordLength = record.length;
            for (var i = 0; i < recordLength; i++) {
                var sName = record[i].name;
                var sValue = record[i].name;

                LexunJS.selectAddOption(obj, sName, sValue);
            }
        }

        function changeTwoDecimal_f(x) {
            var f_x = parseFloat(x);
            if (isNaN(f_x)) {
                //alert('function:changeTwoDecimal->parameter error');
                return false;
            }
            var f_x = Math.round(x * 100) / 100;
            var s_x = f_x.toString();
            var pos_decimal = s_x.indexOf('.');
            if (pos_decimal < 0) {
                pos_decimal = s_x.length;
                s_x += '.';
            }
            while (s_x.length <= pos_decimal + 2) {
                s_x += '0';
            }
            return s_x;
        }
        function toDecimal2(x) {
            var f = parseFloat(x);
            if (isNaN(f)) {
                return false;
            }
            var f = Math.round(x * 100) / 100;
            var s = f.toString();
            var rs = s.indexOf('.');
            if (rs < 0) {
                rs = s.length;
                s += '.';
            }
            while (s.length <= rs + 2) {
                s += '0';
            }
            return s;
        }

        function tootoDecimal(x) {



            if (x.toString().length > 5) {
                return x.toString().substring(0, 5)
            }
            else {
                return x;
            }
            
        }